package dev.touchswipe.shared.components
{
	import dev.touchswipe.shared.components.assets.CheckboxGraphic;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	[Event(name="select",type="flash.events.Event")]
	
	public class Checkbox extends CheckboxGraphic 
	{
		private var _tick:DisplayObject;
		
		public function Checkbox()
		{
			_tick=Sprite(getChildAt(0)).getChildAt(1);
			addEventListener(MouseEvent.CLICK,_toggleState);
		}
		
		private function _toggleState(event:MouseEvent):void{
			_tick.visible=!_tick.visible;
			dispatchEvent(new Event(Event.SELECT));
		}
		
		public function get checked():Boolean{
			return _tick.visible;
		}
		public function set checked(value:Boolean):void{
			_tick.visible=value;
		}
	}
}